package com.qingyun.customview.hencode.practice1

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.fragment.app.Fragment
import com.qingyun.customview.databinding.ActivityPractice1MainBinding
import com.qingyun.customview.databinding.FragmentPageBinding

class PageFragment : Fragment() {


    @LayoutRes
    var sampleLayoutRes: Int = 0

    @LayoutRes
    var practiceLayoutRes: Int = 0
    private lateinit var binding: FragmentPageBinding

    companion object {
        fun newInstance(sampleLayoutRes: Int, practiceLayoutRes: Int): PageFragment {
            return PageFragment().apply {
                arguments = Bundle().apply {
                    putInt("sampleLayoutRes", sampleLayoutRes)
                    putInt("practiceLayoutRes", practiceLayoutRes)
                }
            }
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            sampleLayoutRes = it.getInt("sampleLayoutRes")
            practiceLayoutRes = it.getInt("practiceLayoutRes")
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?,
    ): View? {
        binding = FragmentPageBinding.inflate(inflater, container, false)
        binding.sampleStub.apply {
            layoutResource = sampleLayoutRes
        }.inflate()
        binding.practiceStub.apply {
            layoutResource = practiceLayoutRes
        }.inflate()
        return binding.root
    }
}